package com.springsecurity.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.springsecurity.bean.User;

@RestController
public class WelcomeController {

	@GetMapping(value="index", produces = "text/html;charset=UTF-8")
	public String index(HttpServletRequest req) {
		return "不乱码";
	}
	@GetMapping("/getInfo")
	public String webcome(HttpServletRequest req) {
		SecurityContext ctx = SecurityContextHolder.getContext();
	    Authentication auth = ctx.getAuthentication();
	    User user = (User) auth.getPrincipal();
	    return user.getUsername();
	}
	
//	@GetMapping("/login")
//	public String login() {
//		return "login";
//	}
//	@GetMapping("/register")
//	public String register() {
//		return "register";
//	}
}
